<?php

namespace app\common\service\food\brand;

use api\channel\jutuike\ActivityJutuikeChannle;
use api\channel\jutuike\FoodUnion;
use app\model\BaseSupplier;
use GuzzleHttp\Client;

/**
 *
 */
abstract class FoodBrandBase
{
    public $baseUrl = 'http://openapi.tuikeyun.com';
    public $appId = '10000027';

    /**
     * @var BaseSupplier $supplier
     */
    public $supplier;

    /**
     * @var array
     */
    public $params;

    public function __construct()
    {
        $foodUnion = new ActivityJutuikeChannle();
        $this->supplier = $foodUnion->supplierInfo;
    }

    abstract function getCityRequestUrl();//获取城市列表

    abstract function getStoreListByLocationRequestUrl();//门店列表

    abstract function getStoreMenuRequestUrl();//门店列表

    abstract function getStoreGoodsRequestUrl();//商品详情

    abstract function getOrderCheckRequestUrl();//订单预校验

    abstract function getOrderorderPayRequestUrl();//产品下单

    abstract function getOrderQueryRequestUrl();//订单查询


    /**
     * 获取城市数据
     */
    public function requestGetCity()
    {
        return $this->postData($this->getCityRequestUrl(),$this->params);
    }

    /**
     * 获取门店信息
     */
    public function requestStoreListByLocation()
    {
        return $this->postData($this->getStoreListByLocationRequestUrl(),$this->params);
    }

    /**
     * 获取菜单
     */
    public function requestStoreMenu()
    {
        return $this->postData($this->getStoreMenuRequestUrl(),$this->params);
    }



    /**
     * 聚推客curl请求接口
     * @param $params
     * @param $requestMethod
     * 返回值说明
     * 参数名	必选	 类型	说明
     *  code	是	 int	状态码0 失败 1成功
     *  msg	    是	 string	成功失败信息
     *  data	是	 array	调用成功接口返回的数据
     * @return mixed
     */
    public function postData($requestMethod,$params) {
        $params['app_id'] = $this->appId;
        $params['time'] = time();
        $url = $this->baseUrl . $requestMethod;
        // 签名
        ksort($params);
        $sign = urldecode(http_build_query($params));
        $sign = $sign . '&apisecret='. $this->supplier->api_config['apikey'];
        $params['sign'] = md5($sign);
        $res = curlPost($url, $params);
        $res = json_decode($res, true);
        return $res;
    }


}